
package me.zhengjie.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.base.AjaxResult;
import me.zhengjie.domain.AppDoc;
import me.zhengjie.service.AppDocService;
import me.zhengjie.service.dto.AppDocQueryCriteria;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
* @website https://el-admin.vip
* @author IQW
* @date 2022-07-18
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "文档管理管理")
@RequestMapping("/api/doc")
public class ApiDocController {

    private final AppDocService appDocService;


    @GetMapping("/list")
    @ApiOperation("查询文档管理")
    public ResponseEntity<Object> queryAppDoc(AppDocQueryCriteria criteria,
                                              @PageableDefault(sort = {"docId"}, direction = Sort.Direction.DESC) Pageable pageable){
        return new ResponseEntity<>(appDocService.queryAllApi(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping("/act")
    @ApiOperation("文档收藏或取消收藏")
    public AjaxResult act(@Validated @RequestBody AppDoc resources){
        return  appDocService.actFav(resources) ;
    }

    @PostMapping
    @ApiOperation("新增文档管理")
    public AjaxResult createAppDoc(@Validated @RequestBody AppDoc resources){
        resources.setType(2);   //2知识文档
        resources.setCateId(2); //默认上传到文档库

        appDocService.create(resources);
        return AjaxResult.success("上传成功");
    }


}